//
//  MqFindBikeShopDetailTableViewCell.m
//  Meiqi
//
//  Created by lanou on 16/1/15.
//  Copyright © 2016年 KFC. All rights reserved.
//

#import "MqFindBikeShopDetailTableViewCell.h"

@implementation MqFindBikeShopDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview];
    }
    return self;
}

- (void)addSubview
{
    
    //头像
    _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 50, 50)];
    _imageV.image = [UIImage imageNamed:@"icon_avatar@3x"];
    _imageV.layer.cornerRadius = 25;
    [self.contentView addSubview:_imageV];
    
    //用户
    _usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, kScreenWidth - 100, 30)];
    _usernameLabel.font = [UIFont systemFontOfSize:20];
    [self.contentView addSubview:_usernameLabel];
    
    //点赞按钮
    _goodImageButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _goodImageButton.frame = CGRectMake(kScreenWidth - 80, 0, 30, 30);
    [_goodImageButton setImage:[UIImage imageNamed:@"btn_route_like_selected@3x"] forState:(UIControlStateNormal)];
    [self.contentView addSubview:_goodImageButton];
    
    //点赞Label
    _goodCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 50, 0, 50, 30)];
    [self.contentView addSubview:_goodCountLabel];
    
    
    //星星Label
    _starLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 30, 100, 20)];
    for (int i = 0; i < 5; i ++) {
        UIImageView *starImage = [[UIImageView alloc] initWithFrame:CGRectMake(0 + 20 * i, 0, 20, 20)];
        starImage.image = [UIImage imageNamed:@"icon_shop_detail_noRate@3x"];
        starImage.tag = 50 + i;
        [_starLabel addSubview:starImage];
    }
    [self.contentView addSubview:_starLabel];
    
    //营业时间
    _create_atLabel = [[UILabel alloc] initWithFrame:CGRectMake(180, 30, kScreenWidth - 200, 20)];
    _create_atLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:_create_atLabel];
    
    //评论Label
    _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(70, 60, kScreenWidth - 90, 50)];
    _contentLabel.font = [UIFont systemFontOfSize:15];
    _contentLabel.numberOfLines = 0;
    [self.contentView addSubview:_contentLabel];
    

    //回复人
    _replyLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, _contentLabel.bottom + 10, kScreenWidth - 90, 30)];
    _replyLabel.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:_replyLabel];
    
}
//重写model的set方法
- (void)setModel:(MqFindBikeShopDetailCommentModel *)model
{
    _model = model;
    
    //赋值
    _usernameLabel.text = model.username;
    
    NSInteger num = [model.star integerValue];
    for (int i = 0; i < num; i ++) {
        UIImageView *star = [_starLabel viewWithTag:50 + i];
        star.image = [UIImage imageNamed:@"icon_shop_detail_rate@3x"];
    }
    
    _create_atLabel.text = model.create_at;
    
    _contentLabel.text = model.content;
    [_contentLabel sizeToFit];
    CGFloat contentHeight = _contentLabel.frame.size.height;
    [_contentLabel setFrame:CGRectMake(70, 60, kScreenWidth - 90, contentHeight)];
    
    
    if ([model.reply_to_username isEqualToString:@""]) {
        [_replyLabel setFrame:CGRectMake(70, _contentLabel.bottom + 10, 0, 0)];
    }else
    {
    _replyLabel.text = [NSString stringWithFormat:@"%@:%@",model.reply_to_username,model.reply_to_content];
        [_replyLabel setFrame:CGRectMake(70, _contentLabel.bottom + 10, kScreenWidth - 90, 30)];
    }
    
    _goodCountLabel.text = model.like_count;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
